//
//  RBHomeGoodsRecView.m
//  zhongzhenglu
//
//  Created by XL on 2022/5/26.
//

#import "RBHomeGoodsRecView.h"
#import "RBThemeConfig.h"
#import <Masonry.h>
#import "UIView+RBAdd.h"
#import "RBDefine.h"
#import "UIImageView+RBAdd.h"

@interface RBHomeGoodsRecView()

@property(nonatomic, strong) UIImageView *view1;
@property(nonatomic, strong) UIImageView *view2;
@property(nonatomic, strong) UIImageView *view3;

@end

@implementation RBHomeGoodsRecView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        UIImageView *view1 = [self getAView];
        self.view1 = view1;
        [self addSubview:view1];
        UIImageView *view2 = [self getAView];
        self.view2 = view2;
        [self addSubview:view2];
        UIImageView *view3 = [self getAView];
        self.view3 = view3;
        [self addSubview:view3];
        
        [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(Zoom(15));
            make.top.bottom.mas_equalTo(0);
        }];
        [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(view1.mas_right).offset(Zoom(11));
            make.right.mas_equalTo(Zoom(-15));
            make.top.width.mas_equalTo(view1);
            
        }];
        [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(view2);
            make.bottom.mas_equalTo(view1);
            make.top.mas_equalTo(view2.mas_bottom).offset(Zoom(11));
            make.height.mas_equalTo(view2);
        }];
    }
    return self;
}

+ (CGFloat)suggestViewHeight
{
    return Zoom(214);
}

- (void)setGoods:(NSArray *)goods
{
    if(goods.count < 3)
    {
        return;
    }
    RBHomeGoodsRecModel *model = goods[0];
    [self.view1 setImageWithUrl:model.picurl placeHolder:nil];
    model = goods[1];
    [self.view2 setImageWithUrl:model.picurl placeHolder:nil];
    model = goods[2];
    [self.view3 setImageWithUrl:model.picurl placeHolder:nil];
    
}

- (UIImageView *)getAView
{
    UIImageView *view = UIImageView.new;
    [view rbSetCornerRadius:Zoom(8)];
    view.contentMode = UIViewContentModeScaleAspectFill;
    return view;
}

@end
